﻿using System;
using System.Net;

namespace Salient.Net
{
    ///<summary>
    ///</summary>
    public class ProxyShim : IWebProxy
    {
        ///<summary>
        /// use this delegate or one like it to get yourself in the 
        /// proxy pipeline.
        ///</summary>
        ///<param name = "destination"></param>
        public delegate Uri GetProxyDelegate(Uri destination);

        private readonly GetProxyDelegate _action;

        ///<summary>
        ///</summary>
        ///<param name = "action"></param>
        public ProxyShim(GetProxyDelegate action)
        {
            _action = action;
        }

        #region IWebProxy Members

        /// <summary>
        ///   The credentials to submit to the proxy server for authentication.
        /// </summary>
        /// <returns>
        ///   An <see cref = "T:System.Net.ICredentials" /> instance that contains the credentials that are needed to authenticate a request to the proxy server.
        /// </returns>
        public ICredentials Credentials { get; set; }

        /// <summary>
        ///   Returns the URI of a proxy.
        /// </summary>
        /// <returns>
        ///   A <see cref = "T:System.Uri" /> instance that contains the URI of the proxy used to contact <paramref name = "destination" />.
        /// </returns>
        /// <param name = "destination">
        ///   A <see cref = "T:System.Uri" /> that specifies the requested Internet resource. 
        /// </param>
        public Uri GetProxy(Uri destination)
        {
            return _action(destination);
        }

        /// <summary>
        ///   Indicates that the proxy should not be used for the specified host.
        /// </summary>
        /// <returns>true if the proxy server should not be used for <paramref name = "host" />; otherwise, false.
        /// </returns>
        /// <param name = "host">
        ///   The <see cref = "T:System.Uri" /> of the host to check for proxy use. 
        /// </param>
        public bool IsBypassed(Uri host)
        {
            return false;
        }

        #endregion
    }
}